int x,y;
void (*SIonRedraw)(DISP_OBJ *,int r1,int r2,int r3);
void Draw(DISP_OBJ * db,int r1, int r2,int r3);

void BoardGuiOnRedraw(DISP_OBJ_board * db,int r1, int r2,int r3)
{
  GC *gc=get_DisplayGC();
  SetFont(FONT_E_24R);
  {
    int board_title = Str2ID(stylemsg,0,SID_ANY_LEN);
    DrawString(board_title,2,0,40,240,80,20,0,TEXT_COLOR,0x00000000);
    TextFree(board_title);
    wchar_t skin_text[10];
    snwprintf (skin_text,9,L"Skin %d",skinimg);
    nap2 = Str2ID(skin_text,0,SID_ANY_LEN);
    DrawString(nap2,2,0,260,240,300,20,0,TEXT_COLOR,0x00000000);
    TextFree(nap2);
  }
  GC_PutChar(gc, 0, 63, 240, 205, image1[0].ImageID);
  GC_SetPenColor(gc,LINE_COLOR);
  GC_DrawLine(gc,0,289,240,289);  
  GC_DrawLine(gc,0,28,240,28);
}

extern int GetSkinsCount (const wchar_t *skinspath);
int BoardGuiOnCreate(DISP_OBJ_board *db)
{
  skins_count = GetSkinsCount(L"/card/other/AdvPlayer/skin/");
  return (1);
}

void show_skinimage(void)
{
  wchar_t cskin_image[256];
  snwprintf (cskin_image,255,L"%dselected.png",skinimg);
  REQUEST_IMAGEHANDLER_INTERNAL_UNREGISTER(SYNC,image1[0].ImageHandle,0,0,image1[0].ImageID,1,&error_code);
  RegisterImage(& image1[0], confpath, cskin_image);
}

#define right_key KEY_RIGHT
#define left_key KEY_LEFT
void BoardGuiOnKey(DISP_OBJ_board *db,int key,int,int repeat,int type)
{
  if(type==KBD_SHORT_PRESS || type==KBD_REPEAT)
  {
    if (key==right_key)
    {
      if(skinimg>0 && skinimg<skins_count)
        skinimg+=1;
      
      show_skinimage();
    }
    if (key==left_key)
    {
      if(skinimg<skins_count+1 && skinimg>1)
        skinimg-=1;
      
      show_skinimage();
    }
  }
  DispObject_InvalidateRect(&db->dsp_obj,0);
}

void OnLeftSoftkey(BOOK * bk, GUI *)
{
  snwprintf (skin_to_run,255,L"%d.png",skinimg);  
  minimizeAndSet(confpath,skin_to_run);
}


void OnRightSoftkey(BOOK * bk, GUI *)
{
  MessageBox(0x6fFFFFFF,STR(moreinfo),0, 1 ,0,0);
}

void BoardGui_constr(DISP_DESC *desc)
{
  DISP_DESC_SetName(desc,"Gui_Board");
  DISP_DESC_SetSize(desc,sizeof(DISP_OBJ_board));
  DISP_DESC_SetOnCreate(desc,(DISP_OBJ_ONCREATE_METHOD)BoardGuiOnCreate);
  DISP_DESC_SetOnRedraw(desc,(DISP_OBJ_ONREDRAW_METHOD)BoardGuiOnRedraw);
  DISP_DESC_SetOnKey(desc,(DISP_OBJ_ONKEY_METHOD)BoardGuiOnKey);
}

void BoardGui_destr(GUI *desc)
{
}

void OnCloseBoard(BOOK * bk, GUI *)
{
  BookObj_Hide(FindBook(isRunned),0);
  GUIObject_Destroy(MMSBook->board);
}


GUI_Board *CreateBoardGui(MyBOOK * MSBook)
{
  GUI_Board *gui_board=new GUI_Board;
  if (!GUIObject_Create((GUI *)gui_board,BoardGui_destr,BoardGui_constr, &MSBook->book,0,0,0))
  {
    delete gui_board;
    return 0;
  }
  DISP_OBJ_board *disp_obj;
  disp_obj=(DISP_OBJ_board *)GUIObject_GetDispObject((GUI*)gui_board);
  disp_obj->mb=MSBook;
  MSBook->board=(GUI_type*)gui_board;
  if (MSBook) BookObj_AddGUIObject(&MSBook->book,(GUI*)MSBook->board);
  GUIObject_SetStyle(MSBook->board,4);
  GUIObject_SetTitleType((GUI*)MSBook->board, 1);
  GUIObject_SoftKeys_SetAction(MSBook->board,ACTION_BACK, OnCloseBoard);
  GUIObject_SoftKeys_SetAction(MSBook->board,ACTION_LONG_BACK, OnCloseBoard);
  GUIObject_SoftKeys_SetAction(MSBook->board,ACTION_SELECT, OnLeftSoftkey);
  GUIObject_SoftKeys_SetAction(MSBook->board,ACTION_MORE, OnRightSoftkey);
  show_skinimage();
  return gui_board;
}
